package com.element.music.repository.repository;

import com.element.music.repository.entity.collection.CollectionEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.Optional;

/**
 * 功能描述：
 * <p>
 * User: nft musician developer
 * Date: 2022/1/10
 */

@Repository
public interface CollectionRepository extends JpaRepository<CollectionEntity, Long> {

    /**
     * 根据智能合约地址找collection
     * @param contractAddress 智能合约
     * @return
     */
    CollectionEntity findCollectionEntityByContractAddress(String contractAddress);


    /**
     * 根据智能合约删除collection
     * @param contractAddress 智能合约地址
     * @return
     */
    Boolean deleteByContractAddress(String contractAddress);


    /**
     * 编辑description
     * @param collectionId collectionId
     * @param description description
     */
    @Modifying
    @Query("update CollectionEntity m set m.description= ?2 where m.id=?1")
    void updateCollectionByDescription(Long collectionId, String description);


    /**
     * 编辑website
     * @param collectionId collectionId
     * @param website website
     */
    @Modifying
    @Query("update CollectionEntity m set m.website= ?2 where m.id=?1")
    void updateCollectionByWebsite(Long collectionId, String website);


    /**
     * 编辑twitter
     * @param collectionId collectionId
     * @param twitter twitter
     */
    @Modifying
    @Query("update CollectionEntity m set m.twitter= ?2 where m.id=?1")
    void updateCollectionByTwitter(Long collectionId, String twitter);

    /**
     * 编辑opensea
     * @param collectionId collectionId
     * @param openSea openSea
     */
    @Modifying
    @Query("update CollectionEntity m set m.openSea= ?2 where m.id=?1")
    void updateCollectionByOpenSea(Long collectionId, String openSea);


}
